<template>
  <div class="cart-list">
    <scroll class="content" ref="scroll">
      <div class="list-item" v-for="(item,index) in cartList" :key="index">
        <div class="item-selector">
          <check-button :is-checked="item.checked" @checkClick="checkClick(item)"></check-button>
        </div>
        <div class="item-img">
          <img :src="item.image" alt="">
        </div>
        <div class="item-info">
          <div class="item-title">{{item.title}}</div>
          <div class="item-desc">{{item.desc}}</div>
          <div class="info-bottom">
            <div class="item-price left">¥{{item.price}}</div>
            <div class="item-price right">×{{item.count}}</div>
          </div>
        </div>
      </div>
    </scroll>
  </div>
</template>

<script>
  import {mapGetters} from 'vuex'
  import Scroll from "../../../components/common/scroll/Scroll";
  import CheckButton from "../../../components/content/checkbutton/CheckButton";
  export default {
    name: "CartList",
    components: {
      Scroll,
      CheckButton
    },
    computed: {
      ...mapGetters(['cartList'])
    },
    methods: {
      checkClick(item) {
        item.checked = !item.checked
      }
    },
    activated() {
      this.$refs.scroll.refresh()
    }
  }
</script>

<style scoped>
  .cart-list {
    height: calc(100% - 44px - 49px - 40px);
  }
  .content {
    height: 100%;
    overflow: hidden;
  }
  .list-item {
    width: 100%;
    display: flex;
    font-size: 0;
    padding: 5px;
    border-bottom: 1px solid #ccc;
  }
  .item-selector {
    width: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 5px;
  }
  .item-title, .item-desc {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .item-img img{
    width: 80px;
    height: 100px;
    display: block;
    border-radius: 5px;
  }
  .item-info {
    font-size: 17px;
    color: #333;
    padding: 5px 10px;
    position: relative;
    overflow: hidden;
  }
  .item-info .item-desc {
    font-size: 14px;
    color: #666;
    margin-top: 15px;
  }
  .info-bottom {
    margin-top: 10px;
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
  }
  .info-bottom .item-price {
    color: orangered;
  }
  .info-bottom .right {
    font-size: 14px;
    color: #333;
  }
</style>
